<template>
  <el-form>
    <el-form-item label="旧密码">
      <el-input v-model="userold.oldpassowrd" />
    </el-form-item>
    <el-form-item label="新密码">
      <el-input v-model="userold.newpassword" />
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submit">修改</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { updatePssword } from "@/api/user";
export default {
  data() {
    return {
      userold: {
        urId: 0,
        oldpassowrd: "",
        newpassword: "",
      },
    };
  },
  props: {
    user: {
      type: Object,
      default: () => {
        return {
          name: "",
          email: "",
        };
      },
    },
  },
  methods: {
    submit() {
      if (this.userold.oldpassowrd == "" || this.userold.newpassword == "") {
        this.$message({
          message: "请检查你的密码输入是否有问题!",
          type: "info",
          duration: 5 * 1000,
        });
        return;
      }
      this.userold.urId = this.user.urId;
      updatePssword(
        this.userold.oldpassowrd,
        this.userold.newpassword,
        this.userold.urId
      ).then((res) => {
        if (res.code == 200) {
          this.$message({
            message: "密码修改成功!",
            type: "success",
            duration: 5 * 1000,
          });
          this.userold.oldpassowrd = "";
          this.userold.newpassword = "";
        } else {
          this.$message({
            message: "密码修改失败！",
            type: "info",
            duration: 5 * 1000,
          });
        }
      });
    },
  },
};
</script>
